package com.example.demo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class WebInterceptorConfig extends WebMvcConfigurationSupport {
    @Autowired
    private TestInterceptor testInterceptor;

    //不拦截的URL集合
    private static List<String> exclusionUrlList = new ArrayList<>();

    static {
        exclusionUrlList.add("/favicon.ico");
        exclusionUrlList.add("/**/*.css");
        exclusionUrlList.add("/**/*.js");
        exclusionUrlList.add("/ok");
        exclusionUrlList.add("/");
        exclusionUrlList.add("/console/**");
        exclusionUrlList.add("/index");
    }

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(this.testInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(exclusionUrlList);
        super.addInterceptors(registry);
    }
}
